public class HashBuck<K,V> {
    //哈希桶的模拟实现；
    static class  Node<K,V> {
        public K key;
        public V val;
        public Node<K, V> next;

        public Node(K key, V val) {
            this.key = key;
            this.val = val;
        }
    }
    public int usedSize;
    public Node<K,V>[] array=new Node[10];
    public double load_factor = 0.75;


    public void put(K key,V val) {
        int hash = key.hashCode();
        int index = hash % array.length;

        Node<K,V> cur = array[index];
        while (cur != null) {
            if(cur.key.equals(key)) {
                cur.val = val;
                return;
            }
            cur = cur.next;
        }

        Node<K,V> newNode = new Node<>(key,val);
        newNode.next = array[index];
        array[index] = newNode;
        this.usedSize++;
        //检查负载因子

    }

    public V get(K key) {
        int hash = key.hashCode();
        int index = hash % array.length;

        Node<K,V> cur = array[index];
        while (cur != null) {
            if(cur.key.equals(key)) {
                return cur.val;
            }
            cur = cur.next;
        }
        return null;
    }


}



